package com.github.ilioili.justdoit.common;

import android.util.Log;

import com.github.ilioili.justdoit.common.config.AppConfig;
import com.github.ilioili.justdoit.common.config.Colors;
import com.github.ilioili.justdoit.common.config.EventConstants;
import com.github.ilioili.justdoit.common.config.UserInfo;
import com.github.ilioili.justdoit.model.dao.ScheduleEventDao;
import com.github.ilioili.justdoit.model.pojo.ScheduleEvent;
import com.github.ilioili.justdoit.util.DateRepeatUtil;
import com.github.ilioili.justdoit.util.DateUtil;
import com.github.ilioili.justdoit.util.LanguageUtil;
import com.github.ilioili.justdoit.util.sql.DbUtil;
import com.qiniu.android.common.Zone;
import com.qiniu.android.http.ResponseInfo;
import com.qiniu.android.storage.Configuration;
import com.qiniu.android.storage.UpCompletionHandler;
import com.qiniu.android.storage.UpProgressHandler;
import com.qiniu.android.storage.UploadManager;
import com.qiniu.android.storage.UploadOptions;
import com.qiniu.android.utils.UrlSafeBase64;
import com.taihe.template.base.BaseApplication;
import com.taihe.template.base.util.ToastUtil;

import org.json.JSONException;
import org.json.JSONObject;

import java.io.File;
import java.io.UnsupportedEncodingException;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.util.Calendar;
import java.util.HashMap;
import java.util.Map;

import javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec;

/**
 * Created by hantuo on 16/5/10.
 */
public class App extends BaseApplication {



    /**
     * Computes RFC 2104-compliant HMAC signature.
     * * @param data
     * The data to be signed.
     *
     * @param key The signing key.
     * @return The Base64-encoded RFC 2104-compliant HMAC signature.
     * @throws java.security.SignatureException when signature generation fails
     */



    @Override
    public void onCreate() {
        super.onCreate();
        UserInfo.init(this);
        DbUtil.init(this);
        AppConfig.init(this);
        ToastUtil.init(this);
        LanguageUtil.init(this);
        if (AppConfig.isFirstTime()) {
            ScheduleEvent scheduleEvent = new ScheduleEvent();
            scheduleEvent.name = "每天10000步";
            scheduleEvent.color = Colors.BLUE;
            scheduleEvent.isRepeat = true;
            scheduleEvent.type = EventConstants.TYPE_TARGET;
            scheduleEvent.repeatFlag = DateRepeatUtil.getWeeklyAlldayFlag(true);
            scheduleEvent.createTime = System.currentTimeMillis() - 1l * 24 * 60 * 60 * 1000;
            scheduleEvent.endTime = scheduleEvent.createTime + 30 * DateUtil.DAY_MILISECOND;
            Calendar instance = Calendar.getInstance();
            instance.setTimeInMillis(scheduleEvent.createTime);
            instance.set(Calendar.HOUR_OF_DAY, 0);
            instance.set(Calendar.MINUTE, 0);
            instance.set(Calendar.SECOND, 0);

            scheduleEvent.id = scheduleEvent.createTime;
            scheduleEvent.startTime = scheduleEvent.createTime;
            ScheduleEventDao.replace(scheduleEvent);

            ScheduleEvent event = new ScheduleEvent();
            event.name = "周五给家打电话";
            event.color = Colors.RED;
            event.type = EventConstants.TYPE_HABIT;
            event.isRepeat = true;
            event.repeatFlag = DateRepeatUtil.getWeeklyRepeatFlag(0, Calendar.FRIDAY, true);
            event.createTime = System.currentTimeMillis() - 2l * 24 * 60 * 60 * 1000;
            instance.setTimeInMillis(event.createTime);
            instance.set(Calendar.HOUR_OF_DAY, 0);
            instance.set(Calendar.MINUTE, 0);
            instance.set(Calendar.SECOND, 0);

            event.id = event.createTime;
            event.startTime = event.createTime;
            ScheduleEventDao.replace(event);

            AppConfig.setIsFirstTime(false);
        }
    }
}
